<?php
/**
 * 考勤操作模型
 */

namespace app\common\model;

use think\model\concern\SoftDelete;

class Attendance extends Model
{
    use SoftDelete;
    public $softDelete = true;
    protected $name = 'attendance';
    protected $autoWriteTimestamp = true;

    //可搜索字段
    protected $searchField = [];
    protected $whereField = ['staff_id','department_id','attendance_time'];

    //考勤时间获取器
    public function getAttendanceTimeAttr($value)
    {
        return date('Y-m', $value);
    }

    //考勤时间修改器
    public function setAttendanceTimeAttr($value)
    {
        return strtotime($value);
    }
//    //是否全勤获取器
//    public function getisFullAttr($value, $data)
//    {
//        return self::BOOLEAN_TEXT[$data['is_full']];
//    }
//    //是否新员工获取器
//    public function getisNewAttr($value, $data)
//    {
//        return self::BOOLEAN_TEXT[$data['is_new']];
//    }
    //考勤获取修改器
    public function getlateTimeAttr($value)
    {
        return json_decode($value,true);
    }
    //考勤设置修改器
//    public function setlateTimeAttr($value)
//    {
//        return json_encode($value,true);
//    }

    //附件修改器
    public function setFileAttr($value)
    {
        return json_encode($value);
    }
    //附件获取器
    public function getFileAttr($value)
    {
        return json_decode($value, true);
    }

    //关联员工表
    public function staff()
    {
        return $this->belongsTo(Staff::class);
    }

    //关联职位表
    public function department()
    {
        return $this->belongsTo(Department::class);
    }
}
